package com.lalnou3g.hm0419;

import com.sun.org.apache.bcel.internal.generic.NEW;

import java.io.*;

/**
 * Created by dllo on 18/4/18.
 */
public class Test01 {
    public static void main(String[] args) {
        File aFile = new File("Q1");
        new Thread(new Runnable() {
            @Override
            public void run() {
                writeFile("a", aFile);
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                writeFile("b", aFile);
            }
        }).start();
    }

    public static void writeFile(String fileName, File srcFile) {

        File file = new File("Q2" + File.separator + fileName);
        PrintWriter pw = null;
        try {
            if (!file.exists()) {
                file.createNewFile();
            }
            if (file.length() == 0) {
                pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file)));
                while (true) {
                    pw.println(srcFile);
                    if (file.length() >= 1024 * 1024 * 1024) {
                        break;
                    }
                }
                System.out.println(file.length() + "文件大小");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeAll(pw);
        }
    }

}
